package com.example.zqq.wuzichess;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private ChessPanelView chessView;
    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        chessView = (ChessPanelView) findViewById(R.id.chessView);
        textView = (TextView) findViewById(R.id.text);

        initListener();
    }

    private void initListener() {
        chessView.setSetView(new ChessPanelView.setView() {
            @Override
            public void setview(String s) {
                if (s != null) {
                    textView.setVisibility(View.VISIBLE);
                    textView.setText(s);
                } else {
                    textView.setVisibility(View.GONE);
                    textView.setText("");
                }
            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        //再来一局
        if (id == R.id.action_setting) {
            chessView.start();
            textView.setVisibility(View.GONE);
            textView.setText("");
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }


}
